package com.itgone.view.activity;

import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;

import com.itgone.R;
import com.itgone.bean.User;
import com.itgone.common.Const;
import com.itgone.presenter.IRegisterPresenter;
import com.itgone.presenter.impl.RegisterPresenterImpl;
import com.itgone.view.IRegisterView;

public class RegisterActivity extends BaseActivity implements IRegisterView {


    private AutoCompleteTextView mEtUsername, mEtPassword, mEtEmail, mEtPhone, mEtQuestion, mEtAnswer;
    private Button mBtnRegister, mBtnCancel;

    @Override
    int getLayoutId() {
        return R.layout.activity_register;
    }

    @Override
    protected void initData() {
        IRegisterPresenter registerPresenter = new RegisterPresenterImpl(this);

        mBtnRegister.setOnClickListener(registerPresenter);
        mBtnCancel.setOnClickListener(registerPresenter);
    }

    @Override
    protected void initView() {
        setTitle("用户注册");

        mEtUsername = findViewById(R.id.actv_username);
        mEtPassword = findViewById(R.id.actv_password);
        mEtEmail = findViewById(R.id.actv_email);
        mEtPhone = findViewById(R.id.actv_phone);
        mEtQuestion = findViewById(R.id.actv_question);
        mEtAnswer = findViewById(R.id.actv_answer);

        mBtnRegister = findViewById(R.id.btn_register);
        mBtnCancel = findViewById(R.id.btn_cancel);
    }

    @Override
    public User getRegisterUser() {
        String username = mEtUsername.getText().toString();
        String password = mEtPassword.getText().toString();
        String email = mEtEmail.getText().toString();
        String phone = mEtPhone.getText().toString();
        String question = mEtQuestion.getText().toString();
        String answer = mEtAnswer.getText().toString();
        User user = new User(username, password, email, phone, question, answer);
        return user;
    }

    @Override
    public void setErrorMsg(String type, String error) {
        switch (type) {
            case Const.KEY_USERNAME:
                mEtUsername.setError(error);
                break;
            case Const.KEY_PASSWORD:
                mEtPassword.setError(error);
                break;
            case Const.KEY_EMAIL:
                mEtEmail.setError(error);
                break;
            case Const.KEY_PHONE:
                mEtPhone.setError(error);
                break;
            case Const.KEY_QUESTION:
                mEtQuestion.setError(error);
                break;
            case Const.KEY_ANSWER:
                mEtAnswer.setError(error);
                break;
        }
    }
}
